#ifndef _THREAD_MUTUALLY_EXCLUSIVE_H_
#define _THREAD_MUTUALLY_EXCLUSIVE_H_

#ifdef _WIN32
#include <windows.h>
#include <process.h>
#else
#include <pthread.h>
#endif

class MutuallyExclusive
{
protected:
	// The states that the mutex can be in.
	enum MutexState
	{
		// Mutex is locked, and cannot be used.
		LOCKED,

		// Mutex is currently waiting to be used.
		WAITING,

		// Mutex is available for use.
		AVAILABLE
	};

	// Mutually Exclusive Handler
	HANDLE mutex;

public:
	// Extends and object to be shared between threads.
	MutuallyExclusive();

	// Release the property for use on other threads.
	bool release();
	
	// Wait until the property is available
	DWORD wait(DWORD timeout);

	// Remove the property from being a shared resources.
	~MutuallyExclusive();
};

#endif